package com.ruoyi.web.controller.example;


import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.web.pojo.Address;
import com.sun.net.httpserver.HttpServer;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

@Anonymous
@RestController
public class BindController {
    //尝试接受参数

    //http://localhost:8080/GetName?name=雷军&age=55
    @GetMapping("/GetName")
    public String GetName(HttpServletRequest request) {
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        return "获取的姓名是:" + name + "获取的年龄是:" + age;

    }
    //尝试直接获取，需要定义的变量名和url中的参数名 完全一致
    @GetMapping("/GetName2")
    public String GetName2(String name,String age) {

        return "获取的姓名是:" + name + "获取的年龄是:" + age;

    }
    //restFul 风格

    @GetMapping("/GetName3/{name}")
    public String GetName3(@PathVariable(value = "name")String name){
        return "获取的姓名是:" + name ;

    }
    @PostMapping("/GetUserInfo")
    public String GetUserInfo(@RequestBody Address address){
        String result =
                 "用户的姓名是:" + address.getName()
                + "\n用户的编号是:" + address.getSno()
                + "\n用户的电话是:" + address.getTel()
                + "\n用户的订单是:" + address.getOrderID()
                + "\n用户的地址是:" + address.getAddress();
        return result;
    }
}
